﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;

namespace Wpf
{
    public class Info
    {
        /// <summary>
        /// 打印当前调用函数信息
        /// </summary>
        public static void RecordMethodInfo()
        {
            StackTrace st = new StackTrace(true);
            StackFrame sf = st.GetFrame(1);
            var tid = Thread.CurrentThread.ManagedThreadId;
            var mb = sf.GetMethod();
            int tc = Environment.TickCount;
            string s = string.Format("Time:{0},TID:{1},Method:{2} \t Line:{3} \tFile:{4}",
                tc, tid, mb.Name, sf.GetFileLineNumber(), System.IO.Path.GetFileName(sf.GetFileName()));
            Debug.WriteLine(s);
        }

        public static string GetCallingMethod()
        {
            StackTrace st = new StackTrace(true);
            StackFrame sf = st.GetFrame(1);
            var tid = Thread.CurrentThread.ManagedThreadId;
            var mb = sf.GetMethod();
            return mb.Name;
        }

        public static void GetCallMemberName([CallerMemberName] string name = "")
        {
        }

        public static void GetLineNumber([CallerLineNumber] int lineNumber = -1)
        {
        }

        public static void GetFilePath([CallerFilePath] string filePath = "")
        {
        }
    }
}